home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 19 Normal Mapping / NormalMap / FrameResource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2016-03-02  |  3.0 KB  |  91 lines

  1. #pragma once
  2.  
  3. #include "../../Common/d3dUtil.h"
  4. #include "../../Common/MathHelper.h"
  5. #include "../../Common/UploadBuffer.h"
  6.  
  7. struct ObjectConstants
  8. {
  9.     DirectX::XMFLOAT4X4 World = MathHelper::Identity4x4();
  10.     DirectX::XMFLOAT4X4 TexTransform = MathHelper::Identity4x4();
  11.     UINT     MaterialIndex;
  12.     UINT     ObjPad0;
  13.     UINT     ObjPad1;
  14.     UINT     ObjPad2;
  15. };
  16.  
  17. struct PassConstants
  18. {
  19.     DirectX::XMFLOAT4X4 View = MathHelper::Identity4x4();
  20.     DirectX::XMFLOAT4X4 InvView = MathHelper::Identity4x4();
  21.     DirectX::XMFLOAT4X4 Proj = MathHelper::Identity4x4();
  22.     DirectX::XMFLOAT4X4 InvProj = MathHelper::Identity4x4();
  23.     DirectX::XMFLOAT4X4 ViewProj = MathHelper::Identity4x4();
  24.     DirectX::XMFLOAT4X4 InvViewProj = MathHelper::Identity4x4();
  25.     DirectX::XMFLOAT3 EyePosW = { 0.0f, 0.0f, 0.0f };
  26.     float cbPerObjectPad1 = 0.0f;
  27.     DirectX::XMFLOAT2 RenderTargetSize = { 0.0f, 0.0f };
  28.     DirectX::XMFLOAT2 InvRenderTargetSize = { 0.0f, 0.0f };
  29.     float NearZ = 0.0f;
  30.     float FarZ = 0.0f;
  31.     float TotalTime = 0.0f;
  32.     float DeltaTime = 0.0f;
  33.  
  34.     DirectX::XMFLOAT4 AmbientLight = { 0.0f, 0.0f, 0.0f, 1.0f };
  35.  
  36.     // Indices [0, NUM_DIR_LIGHTS) are directional lights;
  37.     // indices [NUM_DIR_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHTS) are point lights;
  38.     // indices [NUM_DIR_LIGHTS+NUM_POINT_LIGHTS, NUM_DIR_LIGHTS+NUM_POINT_LIGHT+NUM_SPOT_LIGHTS)
  39.     // are spot lights for a maximum of MaxLights per object.
  40.     Light Lights[MaxLights];
  41. };
  42.  
  43. struct MaterialData
  44. {
  45.     DirectX::XMFLOAT4 DiffuseAlbedo = { 1.0f, 1.0f, 1.0f, 1.0f };
  46.     DirectX::XMFLOAT3 FresnelR0 = { 0.01f, 0.01f, 0.01f };
  47.     float Roughness = 0.5f;
  48.  
  49.     // Used in texture mapping.
  50.     DirectX::XMFLOAT4X4 MatTransform = MathHelper::Identity4x4();
  51.  
  52.     UINT DiffuseMapIndex = 0;
  53.     UINT NormalMapIndex = 0;
  54.     UINT MaterialPad1;
  55.     UINT MaterialPad2;
  56. };
  57.  
  58. struct Vertex
  59. {
  60.     DirectX::XMFLOAT3 Pos;
  61.     DirectX::XMFLOAT3 Normal;
  62.     DirectX::XMFLOAT2 TexC;
  63.     DirectX::XMFLOAT3 TangentU;
  64. };
  65.  
  66. // Stores the resources needed for the CPU to build the command lists
  67. // for a frame.  
  68. struct FrameResource
  69. {
  70. public:
  71.     
  72.     FrameResource(ID3D12Device* device, UINT passCount, UINT objectCount, UINT materialCount);
  73.     FrameResource(const FrameResource& rhs) = delete;
  74.     FrameResource& operator=(const FrameResource& rhs) = delete;
  75.     ~FrameResource();
  76.  
  77.     // We cannot reset the allocator until the GPU is done processing the commands.
  78.     // So each frame needs their own allocator.
  79.     Microsoft::WRL::ComPtr<ID3D12CommandAllocator> CmdListAlloc;
  80.  
  81.     // We cannot update a cbuffer until the GPU is done processing the commands
  82.     // that reference it.  So each frame needs their own cbuffers.
  83.     std::unique_ptr<UploadBuffer<PassConstants>> PassCB = nullptr;
  84.     std::unique_ptr<UploadBuffer<ObjectConstants>> ObjectCB = nullptr;
  85.  
  86.     std::unique_ptr<UploadBuffer<MaterialData>> MaterialBuffer = nullptr;
  87.  
  88.     // Fence value to mark commands up to this fence point.  This lets us
  89.     // check if these frame resources are still in use by the GPU.
  90.     UINT64 Fence = 0;
  91. };